WRANGLERS

Bulging waistlines

a range plot showing BMI by gender

Photo by Towfiqu Barbhuiya on Unsplash

Photo by Towfiqu Barbhuiya on Unsplash

I’m in good shape. That shape is round…
— Jarod Kintz


Ingest

country, year, bmi

url_root <- "https://raw.githubusercontent.com/UN-AVT/kamino-source/main/sources/0-shared/data/"

url_file1 <- "bulging-waistlines/mean-body-mass-index-bmi-in-adult-males.csv"
url1 <- paste0(url_root, url_file1)
df_males <- read.csv(url1, header = TRUE, stringsAsFactors = TRUE)
df_males
url_file2 <- "bulging-waistlines/mean-body-mass-index-bmi-in-adult-women.csv"
url2 <- paste0(url_root, url_file2)
df_females <- read.csv(url2, header = TRUE, stringsAsFactors = TRUE)
df_females

Wrangle

join the data sets, filter, clean field names, sort

# full join by all common fields
df_wrangle <- full_join(df_males, df_females, by = c("Entity", "Code", "Year"))

# take latest year
df_wrangle <- filter(df_wrangle, Year == 2016)

# take only countries
df_wrangle <- filter(df_wrangle, nchar(as.character(Code)) > 1)

# clean names with spaces
df_wrangle <- df_wrangle %>% janitor::clean_names()

# calculate the mean for sorting, using rowwise operation
df_wrangle <- df_wrangle %>% rowwise() %>% mutate(MEAN = mean(c(mean_bmi_male, mean_bmi_female), na.rm=T))

# sort by mean
df_wrangle <- df_wrangle[order(df_wrangle$MEAN),]

# retain order using row numbers
df_wrangle$ORDER <- seq.int(nrow(df_wrangle))

df_wrangle

Plot

country bmi values for male and female

  • less than 18.5, it falls within the underweight range
  • 18.5 to <25, it falls within the healthy weight range
  • 25.0 to <30, it falls within the overweight range
  • 30.0 or higher, it falls within the obesity range
  • class 1 obesity: BMI of 30 to < 35
  • class 2 obesity: BMI of 35 to < 40
  • class 3 obesity: BMI of 40 or higher. Class 3 obesity is sometimes categorized as “severe” obesity.
theme_opts <- theme(
    text = element_text(family = "inconsolata", size = 16), 
    plot.title = element_text(color = "black", size = 16, face = "bold"),
    plot.subtitle = element_text(color = "black", size = 12),
    plot.caption = element_text(color = "#555555", size = 10),
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    axis.text.y = element_text(size = 12),
    axis.ticks = element_line(),
    panel.border = element_blank(),
    panel.background = element_blank(),
    panel.grid.major.x = element_blank(),
    panel.grid.major.y = element_blank(),
    panel.grid.minor.x = element_blank(),
    panel.grid.minor.y = element_blank(),
    legend.position='bottom',
    plot.margin = unit(c(0.5,0.25,0.25,0.1), "in")
)

# entity, code, year, mean_bmi_male, mean_bmi_female
# use reorder to retain sort
v1 = ggplot(df_wrangle) + 
  geom_vline(xintercept = 18.5, color = "red", linetype = "dashed") +
  geom_vline(xintercept = 25, linetype = "dashed") +
  geom_vline(xintercept = 30, color = "orange", linetype = "dashed") +
  geom_vline(xintercept = 35, color = "red", linetype = "dashed") +
  geom_vline(xintercept = 40, color = "red", linetype = "dashed") +
  geom_segment(aes(x=mean_bmi_male, y=reorder(entity,ORDER), xend=mean_bmi_female, yend=entity), 
               lineend = "round", linejoin = "round", size=2, color="#cccccc") + 
  geom_point(aes(x=mean_bmi_male, y=entity), shape=22, alpha=1.0, size=2, color="#555555", fill="#555555") +
  geom_point(aes(x=mean_bmi_female, y=entity), shape=22, alpha=1.0, size=2, color="#00E5FF", fill="#00E5FF") +
  scale_x_continuous() +
  scale_y_discrete() +
  labs(title = "Mean BMI Values by Gender", x = NULL, y = NULL) +
  theme_bw() +
  theme_opts

girafe(ggobj = v1, width_svg = 24, height_svg = 36,
       options = list(opts_sizing(rescale = TRUE, width = 0.95)))

References

citations for narrative and data sources

  • Inspiration: The Economist, GO
  • Data Source: Our World in Data, GO